// pagesMine/pages/reportList/reportList.js
import ajax from "../../../utils/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    colorList: ['(180deg, #FFEEBC 0%, #F2BE27 100%)', '(180deg, #7CB5FD 0%, #467EFA 100%)', '(180deg, #E1E1E1 0%, #999999 100%)', '(360deg, #03C726 0%, #AAFCB8 100%)'],
    dataList: [],
    tabActive: 1,
    queryData: {
      total: 0,
      pageSize: 10,
      pageNum: 1
    },
    type: 0
  },
  /**
   * 元素点击事件
   */
  reportItemEvent (event) {
    const item = event.currentTarget.dataset.item
    wx.navigateTo({
      url: `/pagesMine/pages/reportDetails/reportDetails?detailId=${item.id}`,
    })
  },
  /**
   * tab点击事件
   */
  tabEvent(event) {
    this.data.queryData.pageNum = 1
    this.setData({ tabActive: event.currentTarget.dataset.index, dataList: [], })
    this.getRequestList()
  },
  /**
   * 列表点击事件
   */
  reportEvent(event) {
    const { id, lookHousingStatus, lookHousingStatusString } = event.currentTarget.dataset.item
    if (lookHousingStatus == 0) return ajax.showToast(lookHousingStatusString)
    wx.navigateTo({ url: `/pagesMine/pages/reportDetails/reportDetails?detailId=${id}` })
  },
  async getRequestList() {
    ajax.showLoading()
    const { dataList, queryData, tabActive } = this.data
    const res = await ajax.get(`/workorder/lookHousingOrder/reportingList?lookHousingStatus=${tabActive}`).finally(() => (wx.hideLoading(), wx.stopPullDownRefresh()))
    const list = res.rows
    list.forEach(item => {
      const beginTime = ajax.dayjs(item.beginTime).format('YYYY-MM-DD HH:ss')
      const endTime = ajax.dayjs(item.endTime).format('HH:ss')
      item.lookTime = `${beginTime} - ${endTime}`
      item.customerMobile = item.customerMobile ? item.customerMobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : ''
    })
    queryData.total = res.total - 0
    this.setData({ dataList: queryData.pageNum == 1 ? list : dataList.concat(list), queryData })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({type: options.type || 0})
    this.getRequestList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.queryData.pageNum = 1;
    this.getRequestList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    const { queryData, dataList } = this.data
    if (queryData.total == dataList.length) return;
    this.data.queryData.pageNum += 1;
    this.getRequestList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})